package com.ruoyi.common.distributeLock.watch;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.springframework.stereotype.Component;
import com.ruoyi.common.distributeLock.callback.*;
/**
 * @author gim 2023/4/19 10:30
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class ZkWatch implements Watcher {
    private final ZooKeeper zooKeeper;
    private final ZkCallback zkCallback;
    @Override
    public void process(WatchedEvent watchedEvent) {
        switch (watchedEvent.getType()){
            case NodeDeleted:
                log.debug("发现节点删除"+watchedEvent);
                zooKeeper.getChildren("/ruoyi",false,zkCallback,null);
        }

    }
}
